{"ast":null,"code":"var _jsxFileName = \"/data/messenger.client/src/components/Message/Date/index.tsx\",\n  _s = $RefreshSig$();\nimport React from 'react';\nimport { format, isToday, fromUnixTime, formatDistanceToNow } from \"date-fns\";\nimport ruLocale from \"date-fns/locale/ru\";\nimport { jsxDEV as _jsxDEV } from \"react/jsx-dev-runtime\";\nconst getMessageTime = date => {\n  if (isToday(date)) {\n    return format(date, 'HH:mm');\n  } else {\n    return format(date, 'd.MM.yy');\n  }\n};\nconst Date = _ref => {\n  _s();\n  let {\n    message,\n    shortDate = false\n  } = _ref;\n  const [dateTime, setDateTime] = React.useState(0);\n  React.useEffect(() => {\n    if (message.updatedAt) {\n      setDateTime(message.updatedAt);\n    } else if (message.createdAt) {\n      setDateTime(message.createdAt);\n    }\n  }, []);\n  return /*#__PURE__*/_jsxDEV(\"span\", {\n    className: \"message__date\",\n    children: [message.updatedAt && !shortDate && /*#__PURE__*/_jsxDEV(\"p\", {\n      className: \"message__date--updateData\",\n      children: `обновлено ` + formatDistanceToNow(fromUnixTime(dateTime), {\n        addSuffix: true,\n        locale: ruLocale\n      })\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 28,\n      columnNumber: 17\n    }, this), !message.updatedAt && message.createdAt && !shortDate && /*#__PURE__*/_jsxDEV(\"p\", {\n      className: \"message__date--createData\",\n      children: `отправлено ` + formatDistanceToNow(fromUnixTime(dateTime), {\n        addSuffix: true,\n        locale: ruLocale\n      })\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 33,\n      columnNumber: 17\n    }, this), shortDate && /*#__PURE__*/_jsxDEV(\"p\", {\n      className: \"message__date--lastMessage\",\n      children: getMessageTime(fromUnixTime(dateTime))\n    }, void 0, false, {\n      fileName: _jsxFileName,\n      lineNumber: 38,\n      columnNumber: 17\n    }, this)]\n  }, void 0, true, {\n    fileName: _jsxFileName,\n    lineNumber: 26,\n    columnNumber: 9\n  }, this);\n};\n_s(Date, \"6sM2Q13LhwW61tBrFAzAEZsVRhE=\");\n_c = Date;\nexport default Date;\nvar _c;\n$RefreshReg$(_c, \"Date\");","map":{"version":3,"names":["React","format","isToday","fromUnixTime","formatDistanceToNow","ruLocale","getMessageTime","date","Date","message","shortDate","dateTime","setDateTime","useState","useEffect","updatedAt","createdAt","addSuffix","locale"],"sources":["/data/messenger.client/src/components/Message/Date/index.tsx"],"sourcesContent":["import React from 'react';\nimport {MessageDateProps} from \"../../../models/props/MessageDateProps\";\nimport {format, isToday, fromUnixTime, formatDistanceToNow} from \"date-fns\";\nimport ruLocale from \"date-fns/locale/ru\";\n\nconst getMessageTime = (date: Date): string => {\n    if (isToday(date)) {\n        return format(date, 'HH:mm');\n    } else {\n        return format(date, 'd.MM.yy');\n    }\n};\n\nconst Date: React.FC<MessageDateProps> = ({message, shortDate = false}) => {\n    const [dateTime, setDateTime] = React.useState<number>(0);\n\n    React.useEffect(() => {\n        if (message.updatedAt) {\n            setDateTime(message.updatedAt);\n        } else if (message.createdAt) {\n            setDateTime(message.createdAt);\n        }\n    },[]);\n\n    return (\n        <span className='message__date'>\n            {message.updatedAt && !shortDate &&\n                <p className='message__date--updateData'>\n                    {`обновлено ` + formatDistanceToNow(fromUnixTime(dateTime), {addSuffix: true, locale: ruLocale})}\n                </p>\n            }\n            {!message.updatedAt && message.createdAt && !shortDate &&\n                <p className='message__date--createData'>\n                    {`отправлено ` + formatDistanceToNow(fromUnixTime(dateTime), {addSuffix: true, locale: ruLocale})}\n                </p>\n            }\n           {shortDate &&\n                <p className='message__date--lastMessage'>\n                    {getMessageTime(fromUnixTime(dateTime))}\n                </p>\n            }\n        </span>\n    );\n}\n\nexport default Date;"],"mappings":";;AAAA,OAAOA,KAAK,MAAM,OAAO;AAEzB,SAAQC,MAAM,EAAEC,OAAO,EAAEC,YAAY,EAAEC,mBAAmB,QAAO,UAAU;AAC3E,OAAOC,QAAQ,MAAM,oBAAoB;AAAC;AAE1C,MAAMC,cAAc,GAAIC,IAAU,IAAa;EAC3C,IAAIL,OAAO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